/**
 * Definition for singly-linked list.
 **/
  class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }

class Solution {
    public ListNode middleNode(ListNode head) {
        if(head == null){
            return head;
        }
        int length = 0;
        ListNode cur = head;

        while(cur != null){
            length ++;
            cur = cur.next;
        }
        int pos = length / 2;
        cur = head;
        while(pos != 0){
            --pos;
            cur = cur.next;
        }
        return cur;
    }
}